package com.chonor.mall.service.impl;

import com.chonor.mall.domain.OrderReturnApplyParam;
import com.chonor.mall.mapper.OrderMapper;
import com.chonor.mall.mapper.OrderReturnApplyMapper;
import com.chonor.mall.model.Order;
import com.chonor.mall.model.OrderReturnApply;
import com.chonor.mall.service.PortalOrderReturnApplyService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * 订单退货管理Service实现类
 * Created by macro on 2018/10/17.
 */
@Service
public class PortalOrderReturnApplyServiceImpl implements PortalOrderReturnApplyService {
    @Autowired
    private OrderReturnApplyMapper returnApplyMapper;

    @Autowired
    private OrderMapper orderMapper;

    @Override
    public int create(OrderReturnApplyParam returnApply) {
        OrderReturnApply realApply = new OrderReturnApply();
        BeanUtils.copyProperties(returnApply,realApply);
        Order order = orderMapper.selectByPrimaryKey(returnApply.getOrderId());
        realApply.setReturnName(order.getReceiverName());
        realApply.setReturnPhone(order.getReceiverPhone());
        realApply.setReturnAmount(order.getPayAmount());
        realApply.setCreateTime(new Date());
        realApply.setStatus(0);

        //更新订单状态
        Order update  = new Order();
        update.setId(order.getId());
        update.setStatus(5);
        update.setModifyat(new Date());
        orderMapper.updateByPrimaryKeySelective(update);

        return returnApplyMapper.insert(realApply);
    }
}
